#=============================================================================
# Copyright (c) @current_year@, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================

#[=======================================================================[

@_RAPIDS_PROJECT_DOCUMENTATION@

Result Variables
^^^^^^^^^^^^^^^^

This module will set the following variables::

  @project_name_uppercase@_FOUND
  @project_name_uppercase@_VERSION
  @project_name_uppercase@_VERSION_MAJOR
  @project_name_uppercase@_VERSION_MINOR

#]=======================================================================]

@PACKAGE_INIT@

cmake_minimum_required(VERSION @CMAKE_MINIMUM_REQUIRED_VERSION@)

set(rapids_global_languages @_RAPIDS_LANGUAGES@)
foreach(lang IN LISTS rapids_global_languages)
  include("${CMAKE_CURRENT_LIST_DIR}/@project_name@-${lang}-language.cmake")
endforeach()
unset(rapids_global_languages)

include("${CMAKE_CURRENT_LIST_DIR}/@project_name@-dependencies.cmake" OPTIONAL)
include("${CMAKE_CURRENT_LIST_DIR}/@project_name@-targets.cmake" OPTIONAL)

if(@_RAPIDS_HAS_COMPONENTS@)
  set(@project_name@_comp_names @_RAPIDS_COMPONENTS@)
  # find dependencies before creating targets that use them
  # this way if a dependency can't be found we fail
  foreach(comp IN LISTS @project_name@_FIND_COMPONENTS)
    if(${comp} IN_LIST @project_name@_comp_names)
      file(GLOB @project_name@_component_dep_files LIST_DIRECTORIES FALSE
           "${CMAKE_CURRENT_LIST_DIR}/@project_name@-${comp}*-dependencies.cmake")
      foreach(f IN LISTS  @project_name@_component_dep_files)
        include("${f}")
      endforeach()
    endif()
  endforeach()

  foreach(comp IN LISTS @project_name@_FIND_COMPONENTS)
    if(${comp} IN_LIST @project_name@_comp_names)
      file(GLOB @project_name@_component_target_files LIST_DIRECTORIES FALSE
           "${CMAKE_CURRENT_LIST_DIR}/@project_name@-${comp}*-targets.cmake")
      foreach(f IN LISTS  @project_name@_component_target_files)
        include("${f}")
      endforeach()
      set(@project_name@_${comp}_FOUND TRUE)
    endif()
  endforeach()
endif()

include("${CMAKE_CURRENT_LIST_DIR}/@project_name@-config-version.cmake" OPTIONAL)

# Set our version variables
set(@project_name_uppercase@_VERSION_MAJOR @rapids_orig_major_version@)
set(@project_name_uppercase@_VERSION_MINOR @rapids_orig_minor_version@)
set(@project_name_uppercase@_VERSION_PATCH @rapids_orig_patch_version@)
set(@project_name_uppercase@_VERSION @rapids_orig_version@)


set(rapids_global_targets @_RAPIDS_GLOBAL_TARGETS@)
set(rapids_namespaced_global_targets @_RAPIDS_GLOBAL_TARGETS@)
if((NOT "@_RAPIDS_NAMESPACE@" STREQUAL "") AND rapids_namespaced_global_targets)
  list(TRANSFORM rapids_namespaced_global_targets PREPEND "@_RAPIDS_NAMESPACE@")
endif()

foreach(target IN LISTS rapids_namespaced_global_targets)
  if(TARGET ${target})
    get_target_property(_is_imported ${target} IMPORTED)
    get_target_property(_already_global ${target} IMPORTED_GLOBAL)
    if(_is_imported AND NOT _already_global)
      set_target_properties(${target} PROPERTIES IMPORTED_GLOBAL TRUE)
    endif()
  endif()
endforeach()

# For backwards compat
if("rapids_config_@type@" STREQUAL "rapids_config_build")
  foreach(target IN LISTS rapids_global_targets)
    if(TARGET ${target})
      get_target_property(_is_imported ${target} IMPORTED)
      get_target_property(_already_global ${target} IMPORTED_GLOBAL)
      if(_is_imported AND NOT _already_global)
        set_target_properties(${target} PROPERTIES IMPORTED_GLOBAL TRUE)
      endif()
      if(NOT TARGET @_RAPIDS_NAMESPACE@${target})
        add_library(@_RAPIDS_NAMESPACE@${target} ALIAS ${target})
      endif()
    endif()
  endforeach()
endif()

unset(rapids_comp_names)
unset(rapids_comp_unique_ids)
unset(rapids_global_targets)
unset(rapids_namespaced_global_targets)

check_required_components(@project_name@)

set(${CMAKE_FIND_PACKAGE_NAME}_CONFIG "${CMAKE_CURRENT_LIST_FILE}")

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(${CMAKE_FIND_PACKAGE_NAME} CONFIG_MODE)

@_RAPIDS_PROJECT_FINAL_CODE_BLOCK@
